package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Publish;
import com.tanhua.server.service.CommentsService;
import com.tanhua.server.service.MovementsMqService;
import com.tanhua.server.service.VideosService;
import com.tanhua.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideosController {

    @Autowired
    private VideosService videosService;
    @Autowired
    private CommentsService commentsService;
    @PostMapping(value = "/comments/{id}/dislike", name = "小视频评论点赞取消")
    public ResponseEntity dislikeVideosComments(@PathVariable("id") String publishId) throws Exception {
        return videosService.dislikeVideosComments(publishId, 3);
    }
    @PostMapping(value = "/comments/{id}/like", name = "小视频评论点赞")
    public ResponseEntity likeVideosComments(@PathVariable("id") String publishId) throws Exception {
        return videosService.likeVideosComments(publishId, 3);
    }

    @PostMapping(value = "/{id}/comments",name = "发布视频评论")
    public ResponseEntity fbVideosComments(@RequestBody Map map){
        String publishId = (String) map.get("id");
        String comment = (String) map.get("comment");
        return commentsService.fbVideosComments(publishId,comment);
    }

    @GetMapping(value = "/{id}/comments", name = "查询视频评论")
    public ResponseEntity videosComments(@PathVariable("id") String videoId,
                                         @RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer pagesize) throws Exception {
        return commentsService.videosComments(videoId, page, pagesize);
    }
    @GetMapping(value = "/{id}", name = "根据id获取视频动态")
    public ResponseEntity queryMovementsById(@PathVariable("id") String publishId) throws Exception {
        return videosService.queryMovementsById(publishId);
    }

    @PostMapping(value = "/{id}/like", name = "视频点赞")
    public ResponseEntity likeVideos(@PathVariable("id") String publishId) throws Exception {
        return videosService.likeVideos(publishId, 2);
    }

    @PostMapping(value = "/{id}/dislike", name = "视频点赞取消")
    public ResponseEntity likeVideosdislike(@PathVariable("id") String publishId) throws Exception {
        return videosService.likeVideosdislike(publishId, 2);
    }

    @PostMapping(value = "/{uid}/userFocus", name = "关注视频博主")
    public ResponseEntity userFocus(@PathVariable("uid") Long followUserId) throws Exception {
//        followUserId:当前登录人关注的用户id
        return videosService.userFocus(followUserId);
    }

    @PostMapping(value = "/{uid}/userUnFocus", name = "取消关注视频博主")
    public ResponseEntity userUnFocus(@PathVariable("uid") Long followUserId) throws Exception {
//        followUserId:当前登录人关注的用户id
        return videosService.userUnFocus(followUserId);
    }

    @PostMapping(name = "上传小视频")
    public ResponseEntity saveSmallVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws Exception {
//        videoThumbnail: 视频封面
//        videoFile: 小视频本身
        return videosService.saveVideos(videoThumbnail, videoFile);
    }

    @GetMapping(name = "获取小视频列表数据")
    public ResponseEntity videosList(@RequestParam(defaultValue = "1") Integer page,
                                     @RequestParam(defaultValue = "10") Integer pagesize) {
//        videoThumbnail: 视频封面
//        videoFile: 小视频本身
        PageResult pageResult = videosService.videosList(page, pagesize);
        return ResponseEntity.ok(pageResult);
    }
}
